#include "progressbar.h"
#include <unistd.h>
#include <string.h>

//进度条参数
char bar[NUM] = {0};
const char* label = "|/-\\";

//进度条函数实现
void progressbar(int rate){
    if(rate < 0 || rate > 100) return;

    int len = strlen(label);
    printf("[%-100s][%d%%][%c]\r", bar, rate, label[rate % len]);
    //刷新缓冲区
    fflush(stdout);
    bar[rate++] = BODY;
}

//进度条初始化
void initbar(){
    memset(bar, '\0', sizeof(bar));
}
